import rtconfig
from building import *

Import('SDK_LIB')

cwd = GetCurrentDir()

# add the general drivers.
src = Glob('board.c')
src += Glob('CubeMX_Config/Src/stm32h7xx_hal_msp.c')
src += Glob('port/drv_mpu.c')
src += Glob('port/drv_lcd_cdev.c')

if GetDepend(['BSP_USING_FATFS_ROOTFS']):
    src += Glob('port/port_mount_table.c')

if GetDepend(['BSP_USING_SPI_FLASH']):
    src += Glob('port/port_spi_flash.c')

if GetDepend(['BSP_USING_SOFT_SPI0']):
    src += Glob('port/port_sspi_flash.c')       

if GetDepend(['BSP_USING_SDIO']):
    src += Glob('port/port_sdcard.c')

if GetDepend(['BSP_USING_MY_SDIO']):
    src += Glob('port/drv_mysdio.c')        
    src += Glob('port/port_sdcard.c')    

if GetDepend(['BSP_USING_QSPI_FLASH']):
    src += Glob('port/port_ospi_flash.c')    

if GetDepend(['LCD_USING_TFT_ST7789']):
    src += Glob('port/port_spi_st7789.c')    

if GetDepend(['LCD_USING_TFT_ST77916']):
    src += Glob('port/panel_qspi_st77916.c') 

if GetDepend(['LCD_USING_TFT_ST77916_DMA']):
    src += Glob('port/panel_qspi_dma_st77916.c')  


src += Glob('drv_test/octospi.c')  
src += Glob('drv_test/w25q128jv.c')               

# cherryusb
if GetDepend(['RT_CHERRYUSB_DEVICE']):
    src += Glob('cherryusb_dev/usbd_init.c')
    src += Glob('cherryusb_dev/test.c') 
    if GetDepend(['RT_CHERRYUSB_DEVICE_TEMPLATE_NONE']):
        src += Glob('cherryusb_dev/my_msc_blkdev.c') 



if GetDepend(['RT_CHERRYUSB_HOST']):
    src += Glob('cherryusb_host/usbh_init.c')    
    src += Glob('cherryusb_host/test.c')    

path = [cwd]
path += [cwd + '/CubeMX_Config/Inc']
path += [cwd + '/port']

# cherryusb
if GetDepend(['RT_CHERRYUSB_DEVICE']):
    path += [cwd + '/cherryusb_dev']
if GetDepend(['RT_CHERRYUSB_HOST']):
    path += [cwd + '/cherryusb_host']

path += [cwd + '/drv_test']    

startup_path_prefix = SDK_LIB

if rtconfig.PLATFORM in ['gcc']:
    src += [startup_path_prefix + '/STM32H7xx_HAL/CMSIS/Device/ST/STM32H7xx/Source/Templates/gcc/startup_stm32h7b3xx.s']
elif rtconfig.PLATFORM in ['armcc', 'armclang']:
    src += [startup_path_prefix + '/STM32H7xx_HAL/CMSIS/Device/ST/STM32H7xx/Source/Templates/arm/startup_stm32h7b3xx.s']
elif rtconfig.PLATFORM in ['iccarm']:
    src += [startup_path_prefix + '/STM32H7xx_HAL/CMSIS/Device/ST/STM32H7xx/Source/Templates/iar/startup_stm32h7b3xx.s']

# STM32H743xx || STM32H750xx || STM32F753xx
# You can select chips from the list above
CPPDEFINES = ['STM32H7B3xx']
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path, CPPDEFINES = CPPDEFINES)

Return('group')
